package com.eostoken.eos_wallet.mvp.presenter;


import android.app.Activity;
import android.content.Context;

import com.eostoken.eos_wallet.mvp.callback.CommonCallback;
import com.eostoken.eos_wallet.mvp.mode.HomeModel;
import com.eostoken.eos_wallet.mvp.view.HomeView;
import com.fredy.mvp.BasePresenter;

import java.util.Map;

import static com.eostoken.eos_wallet.utils.Constants.ACCOUNTS;
import static com.eostoken.eos_wallet.utils.Constants.ACCOUNT_INFO;
import static com.eostoken.eos_wallet.utils.Constants.BALANCE;
import static com.eostoken.eos_wallet.utils.Constants.GET_BIND_ADDRESS;
import static com.eostoken.eos_wallet.utils.Constants.PRICE;

public class HomePresenterImpl extends BasePresenter<HomeModel, HomeView> implements HomePresenter, CommonCallback {

    private Activity context;

    public HomePresenterImpl(Activity context) {
        super(context);
        this.context = context;
    }

    @Override
    public void onSuccess(Object data, String successMsg, int responseSuccessCode) {
        switch (responseSuccessCode) {
            case BALANCE:
            case ACCOUNTS:
            case PRICE:
            case ACCOUNT_INFO:
            case GET_BIND_ADDRESS:
                try {
                    getView().updateView(data, responseSuccessCode);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
        }
    }

    @Override
    public void onFailure(String msg, int responseFailCode) {
        switch (responseFailCode) {
            case BALANCE:
            case ACCOUNTS:
            case PRICE:
            case ACCOUNT_INFO:
            case GET_BIND_ADDRESS:
                try {
                    getView().onFailure(msg, responseFailCode);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
        }
    }

    @Override
    protected void onViewDestroy() {

    }

    @Override
    public void getData(boolean isRefresh) {

    }

    @Override
    public void getMoreData() {

    }

    @Override
    public void requestCurrencyBalance(Map<String, Object> params) {
//        model.getChainInfo(context, params, true, this, BALANCE);
        model.getCurrencyBalance(context, params, true, this);
    }

    @Override
    public void requestKeyAccounts(Map<String, Object> publickey) {
        model.getKeyAccounts(context, publickey, true, this);
    }

    @Override
    public void requestDIGICCYPrice(String pair) {
        model.getDIGICCYPrice(context, pair, true, this);
    }

    @Override
    public void requestAccountInfo(Map<String, Object> accountName) {
        model.getAccount(context, accountName, true, this);
    }

    @Override
    public void requestGetBindWalletAddress(String params, int type) {
        model.getBindWalletAddress(context, params, type, true, this);
    }
}
